/**
 * \file deserializer.h
 * \brief Deserializer class header
 * \author Marc Laval
 * \version 0.1
 * \date 10/2011
 *
 */

#include <string>
#include <stdexcept>
#include "types.h"

#ifndef _DESERIALIZER_H_
#define _DESERIALIZER_H_

using std::runtime_error;
using std::string;

/*! \brief Deserializes data from a ByteBuffer.
 *  \class Deserializer
 *
 * For each data deserialization, the needed amount of bytes is read from the
 * ByteBuffer and data is rebuild. Position of read in the buffer is increased
 * after each read, so data must be read in the correct order.
 */
class Deserializer
{

protected :
	ByteBuffer * m_buf;	///< Command buffer
	uint32 m_index;			///< Read index

public :

	/*! \brief Standard constructor
	 *  \param buf ByteBuffer containing command raw data
	 */
	Deserializer(ByteBuffer * buf);

	/*! \brief Resets current read index */
	void reset();

	/*! \brief Deserializes an unsigned 8bit int from buffer
	 *  \return data as an unsigned 8bit int
	 */
	uint8 readUInt8();

	/*! \brief Deserializes an unsigned 16bit int from buffer
	 *  \return data as an unsigned 16bit int
	 */
	uint16 readUInt16();

	/*! \brief Deserializes an unsigned 32bit int from buffer
	 *  \return data as an unsigned 32bit int
	 */
	uint32 readUInt32();

	/*! \brief Deserializes an unsigned 64bit int from buffer
	 *  \return data as an unsigned 64bit int
	 */
	uint64 readUInt64();

	/*! \brief Deserializes a boolean from buffer
	 *  \return data as a boolean
	 */
	bool readBool();

	/*! \brief Deserializes a float from buffer
	 *  \return data as a float
	 */
	float readFloat();

	/*! \brief Deserializes a double from buffer
	 *  \return data as a double
	 */
	double readDouble();

	/*! \brief Deserializes a string from buffer
	 *  \return data as a string
	 */
	string readString();

};

#endif //_DESERIALIZER_H_
